import java.lang.reflect.Array;
import java.util.Arrays;

//求数组的平均值
public class Test1 {
    /*public static void main(String[] args) {
        int[] a = {1 , 2 , 3 , 4 , 5};
        System.out.println(avg(a));

    }
    public static int avg(int[] n){
        int sum = 0;
        for (int x:n
             ) {
            sum += x;

        }
        return sum/n.length;
    }*/
    /*public static void main(String[] args) {
        int[] a = {1 , 2 , 3 , 4 , 5 , 6};
        num(a);
        for (int x:a
             ) {
            System.out.print(x);
        }

    }
    public static void num(int[] n){
        if(n.length == 0 || n == null){
            return;
        }
        int left = 0;
        int right = n.length - 1;
        while(left < right && n[left] % 2 != 0){
            left++;
        }
        while(left < right && n[right] % 2 == 0){
            right--;
        }
        if(left < right){
            int temp = n[left];
            n[left] = n[right];
            n[right] = temp;
        }



    }*/
    /*public static void main(String[] args) {
        int[] a = {5, 1, 3, 2, 4};
        bubbleSort(a);
        System.out.println(Arrays.toString(a));

    }

    public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
            }
        }*/
    public static void main(String[] args) {
        int num[] = {2 , 7 , 11 , 15};
        int target = 9;
        System.out.println(Arrays.toString(sum(num, target)));

    }
    public static int[] sum(int[] n , int target){

        for (int i = 0; i < n.length - 1; i++) {
            for (int j = i+1; j < n.length; j++) {//存在几个问题，一是j应该等于i+1，避免重复检查
                if(n[i] + n[j] == target)
                {
                    return new int[] {i,j};
                }
            }
        }
        return new int[] {};
    }
    }




